<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="__UI__/css/bs3/dpl.css" rel="stylesheet" type="text/css" />
<link href="__UI__/css/bs3/bui.css" rel="stylesheet" type="text/css" />
<link href="__UI__/css/style.css" rel="stylesheet" type="text/css" />
<link href="__UI__/uploadify/uploadify.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="__UI__/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="__UI__/uploadify/jquery.uploadify.min.js"></script>
<style type="text/css">

button {
	margin-right:20px;
}

.imageViewTheme .bui-uploader-button-wrap {
	margin-bottom:10px;;
	margin-left:10px;
}

.image{
	float:left;
	width:300px;
	padding:10px auto;
	display:block;
}

.image .photo{
	width:300px;
	height:auto;
	overflow:hidden;
	float:left;
}

.image img{
	display:inline-block;
	width:200px;
	height:auto;
	overflow:hidden;
	float:left;
}

.image .del{
	display:inline-block;
	float:right;
	width:100px;
}

.buttons {
    display: inline-block;
    margin-bottom: 0;
    font-weight: normal;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    background-image: none;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 20px;
    padding: 4px 12px;
    font-size: 14px;
    border-radius: 4px;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    color: #ffffff;
    background-color: #000000;
    border-color: #cccccc;
}

.btns span{
	display:block;
	margin:5px auto;
}

.selects{
	float:left;
	min-height:100px;
	height:auto;
	overflow:hidden;
}

.selects .lists{
	float:left;
	width:220px;
	height:200px;
}

.selects .direction{
	float:left;
	width:80px;
	height:200px;
}

.selects option {
	height:20px;
	line-height:20px;
	padding:2px;
}

</style>
</head>
<body>
<div class="demo-content" style="margin-top:1%;">
    <div class="row" style="margin-left:10px;">
        <form id="J_Form" action="{:U('Home/Datum/edit')}" class="form-horizontal registerform" method="post" enctype="multipart/form-data">
        	<div id="tab" style="margin-left:1%; padding-bottom:20px; padding-top:20px;"></div>
            <div id="panel" class="" style="padding:10px;">
                <input name="uid" type="hidden" value="{:session('gid')}">
                <input name="id" type="hidden" value="{$info.id}">
                <div class="control-group">
					<label class="control-label"><s>*</s>资料名称</label>
					<div class="controls">
						<input type="text" name="title" id="title" datatype="*" nullmsg="请输入资料名称！" data-tip="{text:'请输入资料名称'}" style="width:600px;" value="{$info.title}" />
					</div>
				</div>
                <div class="control-group">
					<label class="control-label">文件类别</label>
					<div class="controls">
						<select name="type" id="type" style="width:620px;">
                        	<if condition="$info.type neq ''">
                            <option value="">请选择类别</option>
                        	<option value="{$info.type}" selected>{$info.type}</option>
                            <else/>
                            <option value="">请选择类别</option>
                            </if>
                        	<volist name="filetype" id="vo">  
								<option value="{$vo.title}">{$vo.title}</option>
							</volist>
						</select>
					</div>
				</div>
                <div class="control-group">
					<label class="control-label">新增类型</label>
					<div class="controls">
						<input type="text" name="file_add" id="file_add" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '请输入类别名称';}" style="width:510px;" />
                        <span class="buttons button-inverse" name="section" id="section">新增类别</span>
					</div>
				</div>
<script type="text/javascript">
	$(function() {
		$('#file_upload').uploadify({
			'formData':{
				'timestamp':'{$Think.const.NOW_TIME}',
				'token':'{$Think.const.NOW_TIME | md5}',
				'url':'{:U("Home/Datum/uploadify/")}',
			},
			'auto' : true,//关闭自动上传
			'removeTimeout' : 5,//文件队列上传完成1秒后删除
			'swf' : '__UI__/uploadify/uploadify.swf',
			'uploader' : '{:U("Home/Datum/uploadify/")}',
			'method' : 'post',  //方法，服务端可以用$_POST数组获取数据
			'buttonText' : '上传文件',//设置按钮文本
			'multi' : false,//允许同时上传多张图片
			'uploadLimit' : 2,//一次最多只允许上传10张图片
			'fileTypeDesc' : 'Image Files',//只允许上传图像
			'fileTypeExts' : '*.pdf',//限制允许上传的图片后缀
			'fileSizeLimit' : '50MB',//限制上传的图片大小
			'onUploadSuccess' : function(file, data, response) {
				var n = parseInt(Math.random()*100);
				var obj = jQuery.parseJSON(data);
				var imgstr = '<li id="'+n+'">'+obj.url+'<a onclick=del("'+n+'","'+obj.url+'") style="margin-left:10px;cursor:pointer;">删除</a></li><input name="files" type="hidden" value="'+obj.url+'">';
				$("#previewImgs").append(imgstr);
				$("#saveurl").append(obj.url+'|');
			}
		});
	});
	
	function del(delName,delId){
		var d='#'+delName;
		var url = '{:U("Home/Datum/dels/")}';
		$.post(url,{'id':delName,'name':delId},function(data){
			$(d).attr("value","");
			$(d).html(data.info);
			$(d).hide(3000);
		},'json');
	}
</script>
                <div class="control-group" style="margin-bottom:20px;">
					<label class="control-label" style="margin-right:10px;"><s></s>上传文件</label>
                    <div class="controls" style="height:auto;">
                    	<input id="file_upload" name="file_upload" type="file" multiple>
                        <ul id="previewImgs">
                        <if condition="$info['files'] neq ''">
                        	<li id="{$info.id}">
                            {$info.files}
                        	<input name="files" type="hidden" value="{$info.files}" id="{$info.id}">
                            <a onclick="del('{$info.id}','{$info.files}')" style="margin-left:10px;cursor:pointer;">删除</a>
                            </li>
                        </if>
                        </ul>
					</div>
                    <div class="controls" style="height:auto;">
                    	<textarea name="uploadfileurl" style="display:none;" id="saveurl"></textarea>
					</div>
				</div>
                
                <div class="row actions-bar">
                	<span id="msgdemo2"></span>
                    <div class="form-actions span13 offset3">
                        <button type="submit" class="button button-primary">保存</button>
                        <button type="reset" class="button">重置</button>
                        <button type="button" class="button button-info" name="backid" id="backid">返回</button>
                    </div>
            	</div>           
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="__UI__/js/config.js"></script>
<script type="text/javascript" src="__UI__/js/bui.js"></script>
<script type="text/javascript" src="__UI__/js/Validform_v5.3.2_min.js"></script>
<script type="text/javascript">
	$(function () {
		$('#section').click(function(){
			var d = $('#file_add').val();
			var s = {:session('gid')};
			if(d == ''){
				BUI.Message.Alert('请输入类别名称！');
			}else{
				$.ajax({
					type:'post',
					url:'{:U("Home/Filetype/add")}',
					dataType:'json',
					data:{title:d,uid:s},
					success:function(data){
						if(data.status == 'y'){
							$("#file_add").attr("value",'');
							$("#type").append( "<option value=" + d +">"+d+"</option>" );
							BUI.Message.Alert('增加成功！');
						}else{
							BUI.Message.Alert('删除失败！');
						}
					}
				});
			}
		});
    });
	$(function () {       
		$('#backid').click(function(){
			top.topManager.openPage({
				id:'datum',
				title:'资料管理',
				href:'{:U("Datum/index")}',
				isClose:true,
				reload:true,
			});
		 });
    });
	top.topManager.closePage('datum');
	top.topManager.closePage('datum_add');
    BUI.use(['bui/tab','bui/mask'],function(Tab){
        var tab = new Tab.TabPanel({
            render:'#tab',
            elCls:'nav-tabs',
            panelContainer:'#panel',
            autoRender:true,
            children:[
                {title:'基本信息',value:'1',selected:true},
            ]
        });
    });
    BUI.use('bui/form', function (Form) {
        new Form.Form({
            srcNode:'#J_Form'
        }).render();
    });
	$(function(){
		$(".registerform").Validform({
			tiptype:function(msg,o,cssctl){
				var objtip=$("#msgdemo2");
				cssctl(objtip,o.type);
				objtip.text(msg);
			},
			ajaxPost:true,
			callback:function(data){
				if(data.status == 'y'){
					top.topManager.openPage({
						id:'datum',
						title:'资料管理',
						href:'{:U("Datum/index")}',
						isClose:true,
						reload:true,
					});
				}
			},
		});
	})
</script>
</body>
</html>